package com.order.api.controller;

import com.order.api.service.OrdersService;
import com.order.api.target.Authorization;
import com.order.api.target.MethodLog;
import com.order.api.vo.BaseResult;
import com.order.api.vo.request.OrdersAddRequest;
import com.order.api.vo.request.OrdersIdRequest;
import com.order.api.vo.request.OrdersUpdateRequest;
import com.order.api.vo.request.PageRequest;
import com.order.api.vo.response.OrdersResponse;
import com.order.api.vo.response.PageResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "订单模块")
@RequestMapping("/orders")
@RestController
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    @ApiOperation("订单详情")
    @Authorization
    @RequestMapping(value = "/detail",method = RequestMethod.POST)
    @MethodLog(optType = "订单详情",systemModel = "订单模块")
    public BaseResult<OrdersResponse> findOrderDetail(@RequestBody OrdersIdRequest request){
       return BaseResult.success(ordersService.findOrder(request));
    }

    @Authorization
    @ApiOperation("订单列表-分页")
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    @MethodLog(optType = "订单列表-分页",systemModel = "订单模块")
    public BaseResult<PageResponse<OrdersResponse>> findOrderList(@RequestBody PageRequest request){
        return BaseResult.success(PageResponse.getInstance(ordersService.findOrderList(request)));
    }

    @Authorization
    @ApiOperation("增加订单")
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @MethodLog(optType = "增加订单",systemModel = "订单模块")
    public BaseResult<String> addOrder(@RequestBody OrdersAddRequest request){
        return BaseResult.judgeOperate(ordersService.addOrder(request));
    }

    @Authorization
    @ApiOperation("修改订单")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @MethodLog(optType = "修改订单",systemModel = "订单模块")
    public BaseResult<String> updateOrder(@RequestBody OrdersUpdateRequest request){
        return BaseResult.judgeOperate(ordersService.updateOrder(request));
    }

    @Authorization
    @ApiOperation("删除订单")
    @RequestMapping(value = "delete",method = RequestMethod.POST)
    @MethodLog(optType = "删除订单",systemModel = "订单模块")
    public BaseResult<String> deleteOrder(@RequestBody OrdersIdRequest request){
        return BaseResult.judgeOperate(ordersService.deleteOrder(request));
    }
}
